﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proyecto7CAD.Properties;
using System.Configuration;
using System.Data;
using System.Data.Sql;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Proyecto7CAD.BDProyecto7DataSetTableAdapters;
using System.Collections;
using System.Web;

namespace Proyecto7CAD
{
    public class TabernaCAD
    {
        private SqlConnection conexion = new SqlConnection(Settings.Default.BDProyecto7ConnectionString);
        public DataTable obtenerObjetosTabernaCAD()
        {
            try
            {
                DataSet bd = new DataSet();
                DataTable tabla = new DataTable();
                TabernaTableAdapter taTableAdaptar = new TabernaTableAdapter();
                tabla = taTableAdaptar.obtenerObjetosTaberna();
                return tabla; 
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet obtenerObjetosNoTabernaCAD()
        {
            try
            {

                //TabernaTableAdapter tabernaTA = new TabernaTableAdapter();
                DataSet bd = new DataSet();

                SqlDataAdapter da = new SqlDataAdapter("SELECT idObjeto, nombreObjeto, descripcionObjeto FROM Objeto WHERE (idObjeto NOT IN(SELECT idObjetoTaberna FROM Taberna))", conexion);
                da.Fill(bd, "objetos");
                return bd;
                //return tabernaTA.obtenerObjetosNoTaberna();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void borrarCAD(int id)
        {
            try
            {
                TabernaTableAdapter tabernaTA = new TabernaTableAdapter();
                tabernaTA.Delete(id);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public void insertarCAD(int id, int precio)
        {
            TabernaTableAdapter tabernaTA = new TabernaTableAdapter();
            tabernaTA.Insert(id, precio);
        }

        public SqlDataReader obtenerObjetosTabernaWebCAD(string aux)
        {
            try
            {   
                // creamos la conexion con la BD
                conexion.Open();
                SqlCommand comando = new SqlCommand(aux, conexion);
                // creamos la query y la ejecutamos
                SqlDataReader dr = comando.ExecuteReader();
                return dr;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //conexion.Close();
            }
        }
    }
}